home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / PCASM1.ZIP / COMPARE.ASM < prev    next >
Assembly Source File  |  1990-07-21  |  5KB  |  143 lines

  1. ;compare. asm  -  comparison with cmpsb
  2. ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3. STACKSEG    SEGMENT   STACK  'STACK'
  4.  
  5.              dw     500h  dup (?)
  6.  
  7. STACKSEG    ENDS
  8. ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  9. DATASTUFF    SEGMENT   PUBLIC  'DATA'
  10.  
  11. ax_byte      db  2
  12. bx_byte      db  2
  13. cx_byte      db  2
  14. dx_byte      db  2
  15. si_byte      db  2
  16. di_byte      db  2
  17. bp_byte      db  2
  18. sp_byte      db  2
  19.  
  20. ; + + + + + + + + + + + + + + + START DATA BELOW THIS LINE
  21. EXTRN  ch1str:BYTE
  22. entry_banner     db  13,10, "Enter a word for a word search", 0
  23. no_match_banner  db  "There was no match", 0
  24. input_buffer     db   80 dup (?) 
  25. letter_count     dw   ?
  26. ; + + + + + + + + + + + + + + + END DATA ABOVE THIS LINE
  27.  
  28. DATASTUFF    ENDS
  29. ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  30. CODESTUFF    SEGMENT   PUBLIC  'CODE'
  31.  
  32. EXTRN  show_regs:NEAR , set_reg_style:NEAR , set_count:NEAR
  33. EXTRN  set_blue:NEAR , get_continue:NEAR
  34.  
  35. EXTRN  get_num:NEAR ,            print_num:NEAR 
  36. EXTRN  get_string:NEAR ,         print_string:NEAR
  37. EXTRN  get_ascii_byte:NEAR  ,    print_ascii_byte:NEAR
  38. EXTRN  get_ascii:NEAR  ,         print_ascii:NEAR
  39. EXTRN  get_hex_byte:NEAR ,       print_hex_byte:NEAR
  40. EXTRN  get_hex:NEAR ,            print_hex:NEAR 
  41. EXTRN  get_binary_byte:NEAR ,    print_binary_byte:NEAR
  42. EXTRN  get_binary:NEAR ,         print_binary:NEAR
  43.  
  44. EXTRN  get_signed_byte:NEAR ,    print_signed_byte:NEAR
  45. EXTRN  get_unsigned_byte:NEAR ,  print_unsigned_byte:NEAR
  46. EXTRN  get_signed:NEAR ,         print_signed:NEAR
  47. EXTRN  get_unsigned:NEAR ,       print_unsigned:NEAR 
  48. EXTRN  get_signed_4byte:NEAR ,   print_signed_4byte:NEAR
  49. EXTRN  get_unsigned_4byte:NEAR , print_unsigned_4byte:NEAR
  50. EXTRN  get_signed_8byte:NEAR ,   print_signed_8byte:NEAR
  51. EXTRN  get_unsigned_8byte:NEAR , print_unsigned_8byte:NEAR
  52.  
  53.        ASSUME cs:CODESTUFF, ds:DATASTUFF
  54.  
  55. ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  56.  
  57. main   proc far
  58. start: push  ds               ; set up for return
  59.        sub   ax,ax
  60.        push  ax
  61.  
  62.        mov   ax, DATASTUFF
  63.        mov   ds,ax
  64.  
  65. ; + + + + + + + + + + + + + + + START CODE BELOW THIS LINE
  66.        mov   ax, seg ch1str      ; load es register
  67.        mov   es, ax
  68.        cld                       ; clear DF (increment)
  69.  
  70. big_loop:
  71.        ; get a word for the word search
  72.        mov   ax, offset entry_banner
  73.        call  print_string
  74.        mov   ax, offset input_buffer
  75.        call  get_string
  76.  
  77.        ; find the end of string
  78.        mov   al, 0               ; compare with 0
  79.        mov   bx, offset input_buffer
  80.        mov   cx, 0               ; letter count
  81. letter_count_loop:
  82.        cmp   al, [bx]            ; compare to 0
  83.        je    end_of_count_loop
  84.        inc   cx                  ; increment count
  85.        inc   bx                  ; increment pointer
  86.        jmp   letter_count_loop
  87. end_of_count_loop:
  88.        jcxz  big_loop    ; if cx = 0, string is empty so redo
  89.        mov   letter_count, cx       ; store our count
  90.  
  91.        ; look for word match
  92.        mov   di, offset ch1str
  93.        mov   cx, $$$$           ; $$$$ = length of ch1str
  94.        sub   cx, letter_count   ; start of last possible match
  95.  
  96. word_search_loop:
  97.        push  di                  ; start of search
  98.        push  cx                  ; character count for ch1str
  99.        mov   si, offset input_buffer
  100.        mov   cx, letter_count
  101.        repe  cmpsb               ; the actual comparison
  102.        je    found_it            ; if equal we matched
  103.  
  104.        ; no match. are we finished?
  105.        pop   cx
  106.        pop   di
  107.        inc   di                  ; move to next character
  108.        loop  word_search_loop
  109.  
  110.        ; we fell through. We finished, but found no match
  111.        mov   ax, offset no_match_banner
  112.        call  print_string
  113.        jmp   big_loop
  114.  
  115. found_it:
  116.        pop   cx                  ; clear cx off the stack
  117.        pop   di                  ; start of the match
  118.        mov   si, offset input_buffer
  119.        mov   cx, 25              ; move 25 characters
  120. transfer_loop:
  121.        mov   al, es:[di]
  122.        mov   [si], al
  123.        inc   si
  124.        inc   di
  125.        loop  transfer_loop
  126.        mov   BYTE PTR [si], 0    ; end of a C string
  127.  
  128.        mov   ax, offset input_buffer
  129.        call  print_string
  130.        jmp   big_loop
  131. ; + + + + + + + + + + + + + + + END CODE ABOVE THIS LINE
  132.  
  133.        ret
  134.  
  135. main   endp
  136.  
  137. CODESTUFF    ENDS
  138. ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  139.  
  140.        END     start
  141.  
  142. 
  143.